home *** CD-ROM | disk | FTP | other *** search
/ Programmers Heaven 2 / Programmers Heaven 2.iso / files / graphics / library / wgt51_r2.zip / WGT5 / SRC / WGTSCROL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-03  |  18.6 KB  |  631 lines

  1. #include <time.h>
  2. #include <malloc.h>
  3. #include <stdlib.h>
  4. #include <mem.h>
  5. #include <wgt5.h>
  6.  
  7. /*
  8. m
  9. ╔═════════════════════════════════════════════════════════════════╗
  10. ║             █▓▒░ WordUp Graphics Toolkit V5.0 ░▒▓█              ║
  11. ║         Source Code    Copyright 1995 Egerter Software          ║
  12. ╟─────────────────────────────────────────────────────────────────╢
  13. ║ Module:       wgtscrol.c                                        ║
  14. ║ Contains:     A full scrolling game engine.                     ║
  15. ║               wloadmap, wsavemap, soverlap, wscrollwindow,      ║
  16. ║               wshowwindow, winitscroll,                         ║
  17. ║               wgetworldblock, wputworldblock, wshowobjects,     ║
  18. ║               wfreemap, wendscroll, wcopyscroll,                ║
  19. ║               wgetworldpixel, is_in_window, wscreen_coordx,     ║
  20. ║               wscreen_coordy, wcopymap                          ║
  21. ║                                                                 ║
  22. ║ Last Revised: April 25, 1995                                    ║
  23. ║                                                                 ║
  24. ║ Written by:   Chris Egerter         WATCOM PROTECTED MODE!      ║
  25. ╚═════════════════════════════════════════════════════════════════╝
  26. */
  27.  
  28. static struct {
  29.   char patch_id[8];
  30.   char fname[12];
  31.   float version;
  32. } patch_struct = {"WGTPATCH", "wgtscrol", 1.0} ;
  33.  
  34. #pragma aux putxray "_*" parm caller [edi] [esi] [ebx] modify exact [eax ebx ecx esi edi];
  35. extern void putxray (void *dst, void *src, int len);
  36.  
  37. int transparenttile;
  38.  
  39.  
  40. short skippedframe = 0, noscrollupdate = 0;
  41.  
  42. #define NORMAL 0
  43. #define PARALLAX 1
  44. #define MAXWINDOWS 50
  45.  
  46. /* users should know about these */
  47. block *scrolltiles[MAXWINDOWS];
  48. wgtmap scrollmaps[MAXWINDOWS];
  49.  
  50. wgtmap scrollblock[MAXWINDOWS];
  51.   /* Holds the image for the scrolling window */
  52.  
  53. short mapwidth[MAXWINDOWS], mapheight[MAXWINDOWS];
  54.   /* the width and height (in tiles) of the current map loaded */
  55.  
  56. short tilewidth[MAXWINDOWS], tileheight[MAXWINDOWS];
  57.   /* the width and height (in pixels) of tiles */
  58.  
  59. typedef struct {                 /* object structure */
  60.         char on;                 /* sprite is turned on=1 */
  61.         short x;                 /* world x coordinate  */
  62.         short y;                 /* world y coordinate  */
  63.         unsigned short num;      /* sprite # from sprites array to show  */
  64.         } scrollsprite;
  65.  
  66. short wgtparallax;
  67.  
  68. short windowminx[MAXWINDOWS], windowminy[MAXWINDOWS],
  69.       windowmaxx[MAXWINDOWS], windowmaxy[MAXWINDOWS];
  70.       /* coords of scrolling area */
  71.  
  72. short worldx[MAXWINDOWS];
  73. short worldy[MAXWINDOWS]; /* world coordinates of top left corner of
  74.                              scrolling window */
  75.  
  76. short worldmaxx[MAXWINDOWS], worldmaxy[MAXWINDOWS];
  77.  /* world max x and y for window. These are calculated so you can't scroll
  78.     past the end of the world, depends on window size */
  79.  
  80. short windowwidth[MAXWINDOWS], windowheight[MAXWINDOWS];
  81.  /* Size of window (in tiles) */
  82.  
  83. /* A copyright statement to store in executables  */
  84. char *copyrscroll="WordUp Graphics Toolkit:Multidirectional Scrolling Library Copyright 1995 Egerter Software";
  85.  
  86.  
  87. /* externals */
  88. extern short tx,ty,bx,by;                         /* clipping vars */
  89.                                 /* top x, top y, bottom x, bottom y */
  90.  
  91.  
  92. /* funcs */
  93. void winitscroll (short currentwindow, short mode, short link, short xwidth,
  94.                   short ywidth, block *tileref);
  95.  /* defines window size, and sets up vars */
  96.  
  97. void wshowwindow (short currentwindow, short posx, short posy);
  98.  /* draw the tiles on at a beginning place and sets up more vars */
  99.  
  100. void wscrollwindow (short currentwindow, short wspeedx, short wspeedy);
  101.  /* scroll the screen */
  102.  
  103. void wshowobjects (short currentwindow, short start, short end,
  104.                    block *sprites, scrollsprite *wobjects);
  105.  /* draw the objects onto scroll1 */
  106.  
  107. short wgetworldblock (short currentwindow, short posx, short posy);
  108.  /* returns the tile number at a world coordinate */
  109.  
  110. void wputworldblock (short currentwindow, short posx, short posy,
  111.                      short tilenum);
  112.  /* puts a tile at a world coordinate */
  113.  
  114. void wcopyscroll (short currentwindow, short x, short y);
  115.  /* copies scroll1 onto visual screen */
  116.  
  117. void wendscroll (short currentwindow);
  118.  /* frees blocks, and shuts down scrolling */
  119.  
  120. void wfreemap (wgtmap map);
  121.  /* deallocates memory for a map */
  122.  
  123. short soverlap (short s1, scrollsprite *wobjects1, block *sprites1,
  124.                 short s2, scrollsprite *wobjects2, block *sprites2);
  125.  /* sees if two objects overlap */
  126.  
  127. short windowmode[MAXWINDOWS];     /* Mode for each window (norm or para) */
  128.  
  129.  
  130.  
  131. wgtmap wloadmap (short currentwindow, char *mapfile, short *tiletypes, 
  132.                  scrollsprite *wobjects)
  133. /* Loads a map file into memory */
  134. {
  135.     wgtmap ptr,orig;
  136.     short ctr, mapver; 
  137.     unsigned short size;
  138.     
  139.     if (wgtlibrary == NULL)
  140.     {
  141.         if ((libf = fopen (mapfile, "rb")) == NULL)
  142.             return NULL;
  143.     }
  144.     else 
  145.     {
  146.         if ((libf = fopen (wgtlibrary, "rb")) == NULL)
  147.             return NULL;
  148.         readheader ();
  149.         findfile (mapfile);
  150.         if (lresult == 1)
  151.             fseek (libf, lfpos, SEEK_SET);
  152.         if (checkpassword (password) == 0)
  153.         {
  154.             wsetmode (3);
  155.             printf ("Incorrect password");
  156.             exit (1);
  157.         }
  158.     }
  159.     
  160.     if ((wgtlibrary != NULL) & (lresult == 0)) goto mapstop;
  161.     
  162.     fread (&mapver, 2, 1, libf);
  163.     if (mapver != 8975)
  164.     /* not a map file */
  165.     {
  166.         wsetmode (3);
  167.         printf ("Invalid map header: %i\n", mapver);
  168.         if ((mapver > 8971) && (mapver < 8975))
  169.         {
  170.           printf ("This is an earlier WGT map file (not 5.0). Please use the Map Maker to\n");
  171.           printf ("convert it to 5.0 format.\n");
  172.         }
  173.         exit (1);
  174.     }
  175.     fread (&mapwidth[currentwindow], 2, 1, libf);
  176.     fread (&mapheight[currentwindow], 2, 1, libf);
  177.     
  178.     size = mapheight[currentwindow]*mapwidth[currentwindow] * 2;
  179.     ptr = (wgtmap)malloc (size);                 /* allocate memory */
  180.  
  181.     if (ptr == NULL) return NULL;           /* out of memory? */
  182.     orig = ptr;                             /* original ptr stored */
  183.     if (fread (ptr, size, 1, libf) < 1)     /* read in the data */
  184.     {
  185.       wsetmode (3);
  186.       printf ("Read Failed (MAP).\n");
  187.       exit (1);                             
  188.     }
  189.  
  190.     fread (tiletypes, 256, 2, libf);        /* load tile types */
  191.     fread (&ctr, 2, 1, libf);               /* number of objects stored in file  */
  192.     fread (&wobjects[0], 7, ctr, libf);     /* read ctr object structures */
  193.  
  194.     worldmaxx[currentwindow] = mapwidth[currentwindow] * tilewidth[currentwindow] 
  195.                              - (windowwidth[currentwindow] * tilewidth[currentwindow]) + 1;
  196.  
  197.     worldmaxy[currentwindow] = mapheight[currentwindow] * tileheight[currentwindow] 
  198.                              - (windowheight[currentwindow] * tileheight[currentwindow]) + 1;
  199.     /* Set maximum scrolling values, ie worldx cannot go past worldmaxx */
  200.     scrollmaps[currentwindow]=orig;
  201.     mapstop:
  202.     ;
  203.     fclose (libf);
  204.     return orig;
  205. }
  206.  
  207.  
  208. void wsavemap (short currentwindow, char *filename, wgtmap savemap, 
  209.                short *tiletypes, scrollsprite *wobjects, short numobj)
  210. /* Saves a map file using current object positions
  211.    Useful for saving games in the middle of playing a map
  212.    so you don't have to save games at the start of a level only */
  213.  {
  214.     FILE *fp;
  215.     unsigned short size;
  216.     
  217.     fp = fopen (filename, "wb");                /* open the file */
  218.     size = 8975;
  219.     fwrite (&size, 2, 1, fp);                   /* write the magic number */
  220.     fwrite (&mapwidth[currentwindow], 2, 1, fp);/* write dimensions */
  221.     fwrite (&mapheight[currentwindow], 2, 1, fp);
  222.     
  223.     size = mapheight[currentwindow] * mapwidth[currentwindow] * 2; /* find size */
  224.     fwrite (savemap, size, 1, fp);              /* write size bytes of data from map ptr */
  225.     fwrite (tiletypes, 256, 2, fp);
  226.     size = numobj+1;
  227.     fwrite (&size, 2, 1, fp);
  228.     if (numobj > 0)
  229.       fwrite (&wobjects[0], 7*numobj, 1, fp);   /* write object structures */
  230.     fclose (fp);
  231. }
  232.  
  233.  
  234. short soverlap (short s1, scrollsprite *wobjects1, block *sprites1,
  235.                 short s2, scrollsprite *wobjects2, block *sprites2)
  236. /* Sees if two objects overlap, by comparing the rectangles each are
  237.    contained in.  Pixel precise detection is NOT possible with WGT
  238.    routines. */
  239. {
  240.     short n1,n2;
  241.     short sw1,sh1,sw2,sh2;  /* width/height of both sprites */
  242.     scrollsprite *obj1;
  243.     scrollsprite *obj2;
  244.     block image;
  245.  
  246.     obj1=&wobjects1[s1];
  247.     obj2=&wobjects2[s2];
  248.  
  249.  
  250.     if ((obj1->on & obj2->on)) /* Are they both on? */
  251.     {
  252.         n1 = obj1->num;  /* for easier reading */
  253.         n2 = obj2->num;
  254.  
  255.         image = sprites1[n1];
  256.         sw1= *(short *)image;    /* Width is first 2 bytes of data */
  257.         image+=2;
  258.         sh1= *(short *)image;    /* Height is next 2 bytes of data */
  259.  
  260.         image=sprites2[n2];
  261.         sw2= *(short *)image;    
  262.         image+=2;
  263.         sh2= *(short *)image;
  264.  
  265.         if (( obj2->x >= obj1->x - sw2 ) &&
  266.             ( obj2->x <= obj1->x + sw1 ) &&  /* check all four corners */
  267.             ( obj2->y >= obj1->y - sh2 ) &&
  268.             ( obj2->y <= obj1->y + sh1 )) return 1;
  269.     }
  270.     return 0; /* not colliding */
  271. }
  272.  
  273.  
  274. void wscrollwindow (short currentwindow, short wspeedx, short wspeedy)
  275. {
  276.   short ox1, oy1, ox2, oy2;
  277.   short mode;
  278.   block oldscreen;
  279.   short x, y;
  280.   short x2, y2;
  281.   short a, b;
  282.   short sx, sy;
  283.   short startx;
  284.   short tile;
  285.   short trans;
  286.   short addwidth;
  287.   wgtmap tempmap;
  288.   block  *tiles;
  289.  
  290.   tiles = scrolltiles[currentwindow];
  291.  
  292.   oldscreen = abuf;
  293.   ox1 = tx;
  294.   oy1 = ty;
  295.   ox2 = bx;
  296.   oy2 = by;
  297.  
  298.   worldx[currentwindow] += wspeedx;
  299.   worldy[currentwindow] += wspeedy;
  300.  
  301.   if (worldx[currentwindow] < 0)
  302.     worldx[currentwindow] = 0;
  303.  
  304.   if (worldy[currentwindow] < 0)
  305.     worldy[currentwindow] = 0;
  306.  
  307.   if (worldx[currentwindow] > worldmaxx[currentwindow] -1)
  308.     worldx[currentwindow] = worldmaxx[currentwindow] - 1;
  309.  
  310.   if (worldy[currentwindow] > worldmaxy[currentwindow] - 1)
  311.     worldy[currentwindow] = worldmaxy[currentwindow] - 1;
  312.  
  313.   mode = windowmode[currentwindow];
  314.  
  315.   if (mode == 0)
  316.     trans = -1;
  317.   else
  318.     trans = transparenttile;
  319.  
  320.   wsetscreen ((block)scrollblock[currentwindow]);
  321.   wclip (0, 0, windowmaxx[currentwindow], windowmaxy[currentwindow]);
  322.  
  323.   x = worldx[currentwindow];
  324.   y = worldy[currentwindow];
  325.  
  326.   x2 = x / tilewidth[currentwindow];
  327.   y2 = y / tileheight[currentwindow];
  328.  
  329.   sy = - (y % tileheight[currentwindow]);
  330.   startx = - (x % tilewidth[currentwindow]);
  331.  
  332.   tempmap = (wgtmap)scrollmaps[currentwindow];
  333.   /* Make a ptr to the map */
  334.  
  335.   tempmap += y2 * mapwidth[currentwindow] + x2;
  336.   /* Move to the offset of the tile we want */
  337.  
  338.   x = x2;
  339.   x2 += windowwidth[currentwindow] + 1;
  340.   y = y2;
  341.   y2 += windowheight[currentwindow] + 1;
  342.  
  343.   addwidth = 0;
  344.   if (x2 > mapwidth[currentwindow])
  345.   {
  346.     addwidth = x2 - mapwidth[currentwindow];
  347.     x2 = mapwidth[currentwindow];
  348.   }
  349.   if (y2 > mapheight[currentwindow])
  350.     y2 = mapheight[currentwindow];
  351.   addwidth += mapwidth[currentwindow] - windowwidth[currentwindow] - 1;
  352.   for (b = y; b < y2; b++)
  353.   {
  354.     sx = startx;
  355.     for (a = x; a < x2; a++)
  356.     {
  357.       tile = *tempmap++;
  358.       if ((tiles[tile] != NULL) && (tile != trans))
  359.         wputblock (sx, sy, tiles[tile], mode);
  360.       sx += tilewidth[currentwindow];
  361.     }
  362.     sy += tileheight[currentwindow];
  363.     tempmap += addwidth;
  364.   }
  365.   if (oldscreen != 0xa0000)
  366.     wsetscreen (oldscreen);
  367.   else wsetscreen (NULL);
  368.   tx = ox1;
  369.   ty = oy1;
  370.   bx = ox2;
  371.   by = oy2;
  372. }
  373.  
  374.  
  375.  
  376. void set_transparent_tile (short tile)
  377. {
  378.   transparenttile = tile;
  379. }
  380.  
  381.  
  382.  
  383. void wshowwindow (short currentwindow, short posx, short posy)
  384. /* Starts looking at the scrolling world at posx,posy tiles from the
  385.    top left corner  (0,0) is the top corner. */
  386. {
  387.   worldx[currentwindow] = posx * tilewidth[currentwindow];
  388.   worldy[currentwindow] = posy * tileheight[currentwindow];
  389.  
  390.   //wscrollwindow (currentwindow, 0, 0);
  391. }
  392.  
  393.  
  394.  
  395. void winitscroll (short currentwindow, short mode, short link, short xwidth,
  396.                   short ywidth, block *tileref)
  397. {
  398. short tw,th;
  399. block tileptr;
  400.  
  401.  scrolltiles[currentwindow] = tileref;
  402.  windowmode[currentwindow] = mode;
  403.  
  404.  tw = -1;
  405.  do {
  406.      tw++;
  407.  } while ((tileref[tw] == NULL) & (tw < 256));
  408.  
  409.  tileptr = tileref[tw];
  410.  tw = *(short *)tileptr;
  411.  tileptr += 2;
  412.  th = *(short *)tileptr;
  413.  
  414.  tilewidth[currentwindow] = tw;
  415.  tileheight[currentwindow] = th;
  416.  
  417.  //if ((xwidth > WGT_SYS.xres/tw) || (ywidth > WGT_SYS.yres/th) || (xwidth < 2) || (ywidth < 2))
  418.    /* Invalid window size */
  419.    //{
  420.     //wsetmode (3);
  421.     //printf ("\nInvalid scroll window in call to winitscroll!");
  422.     //exit (1);
  423.    //}
  424.  
  425.  windowminx[currentwindow] = 0;
  426.  windowminy[currentwindow] = 0;
  427.  windowmaxx[currentwindow] = xwidth * tilewidth[currentwindow] - 1;
  428.  windowmaxy[currentwindow] = ywidth * tileheight[currentwindow] - 1;
  429.  /* coords of scrolling area */
  430.  
  431.  if (mode == PARALLAX)
  432.      scrollblock[currentwindow] = scrollblock[link];
  433.  else
  434.      scrollblock[currentwindow] = (wgtmap)wallocblock (
  435.                 windowmaxx[currentwindow]+1, windowmaxy[currentwindow]+1);
  436.  
  437.  windowwidth[currentwindow] = xwidth;
  438.  windowheight[currentwindow] = ywidth;
  439.  /* Set up window widths and heights */
  440. }
  441.  
  442.  
  443.  
  444. short wgetworldblock (short currentwindow, short posx, short posy)
  445. /* Returns a tile from the location on a map */
  446. {
  447.   wgtmap tempmap;
  448.  
  449.   posx = posx / tilewidth[currentwindow];
  450.   posy = posy / tileheight[currentwindow];
  451.   /* Divide by tile size to convert world coords to map coords */
  452.  
  453.   if ((posx < mapwidth[currentwindow]) && (posy < mapheight[currentwindow]) && (posx >= 0) && (posy >= 0))
  454.   {
  455.     tempmap = (wgtmap)scrollmaps[currentwindow];
  456.     /* Make a ptr to the map */
  457.  
  458.     tempmap += posy * mapwidth[currentwindow] + posx;
  459.     /* Move to the offset of the tile we want */
  460.  
  461.     return (*tempmap); /* Return the character at that position */
  462.   }
  463.   else return (-1);
  464. }
  465.  
  466.  
  467.  
  468. void wputworldblock (short currentwindow, short posx2, short posy2,
  469.                      short tilenum)
  470. /* Puts a tile onto the map at the given world coordinates. */
  471. {
  472.   wgtmap tempmap;
  473.  
  474.   posx2 = posx2 / tilewidth[currentwindow];
  475.   posy2 = posy2 / tileheight[currentwindow];
  476.   /* Convert world coords to map coords by dividing by tile size */
  477.  
  478.   if ((posx2 >= 0) && (posx2 < mapwidth[currentwindow]) && (posy2 >= 0) && (posy2 < mapheight[currentwindow]))
  479.   {
  480.     tempmap  = scrollmaps[currentwindow];
  481.     tempmap += posy2 * mapwidth[currentwindow] + posx2;
  482.     *tempmap = tilenum;
  483.     /* Put a character to the map */
  484.   }
  485. }
  486.  
  487.  
  488.  
  489. void wshowobjects (short currentwindow, short start, short end,
  490.                    block *sprites, scrollsprite *wobjects)
  491. /* Display the objects on top of the assembled data screen */
  492. {
  493.   block spriteptr;
  494.   short sw,sh;
  495.   short i;
  496.   short ox1, oy1, ox2, oy2;
  497.   block oldscreen;
  498.  
  499.   ox1 = tx;
  500.   oy1 = ty;
  501.   ox2 = bx;
  502.   oy2 = by;
  503.   oldscreen = abuf;
  504.  
  505.   wsetscreen ((block)scrollblock[currentwindow]);
  506.   wclip (0, 0, windowmaxx[currentwindow], windowmaxy[currentwindow]);
  507.  
  508.  /* Go through sprites, from start to end, and draw them */
  509.  for (i = start; i <= end; i++)
  510.  {
  511.    spriteptr = sprites[wobjects[i].num];
  512.  
  513.    if ((wobjects[i].on) && (spriteptr != NULL))
  514.    /* Make sure the object is on, and the block isn't null */
  515.    {
  516.      sw = *(short *)spriteptr;
  517.      spriteptr += 2;
  518.      sh = *(short *)spriteptr;
  519.      spriteptr -= 2;
  520.  
  521.      if ((wobjects[i].x < worldx[currentwindow] + windowmaxx[currentwindow]) &&
  522.          (wobjects[i].y < worldy[currentwindow] + windowmaxy[currentwindow]) &&
  523.          (wobjects[i].x + sw > worldx[currentwindow]) &&
  524.          (wobjects[i].y + sh > worldy[currentwindow]))
  525.           /* Check to see if the object is on the screen */
  526.  
  527.        wputblock (wobjects[i].x - worldx[currentwindow], wobjects[i].y - worldy[currentwindow], spriteptr, 1);
  528.        /* Put the block onto the scroll1 block */
  529.     }
  530.   }
  531.   if (oldscreen != 0xa0000)
  532.     wsetscreen (oldscreen);
  533.   else wsetscreen (NULL);
  534.   tx = ox1;
  535.   ty = oy1;
  536.   bx = ox2;
  537.   by = oy2;
  538. }
  539.  
  540.  
  541.  
  542. void wfreemap (wgtmap ptr)
  543. /* Frees memory from a map file */
  544. {
  545.   free (ptr);
  546. }
  547.  
  548.  
  549.  
  550. void wendscroll (short currentwindow)
  551. /* Closes up scrolling, and frees virtual screens */
  552. {
  553.   if (scrollblock[currentwindow] != NULL)
  554.      wfreeblock ((block)scrollblock[currentwindow]);
  555.  
  556.   scrollblock[currentwindow] = NULL;
  557.  
  558.   wsetscreen (NULL);
  559. }
  560.  
  561.  
  562.  
  563. unsigned char wgetworldpixel(short currentwindow,  short x, short y)
  564. /* Returns the pixel colour at the specified offset within a tile,
  565.    given the world coordinates in pixels. */
  566. {
  567.   block emsbl;
  568.   block *blockref;
  569.   short tile;          /* Tile number to check */
  570.   short xcoord,ycoord; /* Offset into tile (0-15) */
  571.  
  572.   blockref = scrolltiles[currentwindow];
  573.  
  574.   tile = wgetworldblock(currentwindow, x, y);
  575.  
  576.   emsbl = blockref[tile];
  577.   /* Set a ptr to the block */
  578.  
  579.   xcoord = x % tilewidth[currentwindow]; /* Get x and y offset into tile */
  580.   ycoord = y % tileheight[currentwindow];
  581.  
  582.   emsbl += ycoord * tilewidth[currentwindow] + xcoord + 4;
  583.   /* Move to the correct offset, plus 4 to
  584.      skip over the width and height bytes stored in the block.
  585.      Now we've located the correct tile, and moved to the correct pixel precise
  586.      offset within that tile. */
  587.  
  588.   return *emsbl;
  589. }
  590.  
  591.  
  592.  
  593. short is_in_window(short currentwindow, short x, short y, short range)
  594. /* Returns 1 if coordinate is on screen */
  595. /* Give a 50 pixel extra range for realism */
  596. {
  597. if ((x < worldx[currentwindow] + windowmaxx[currentwindow] + range) &
  598.     (y < worldy[currentwindow] + windowmaxy[currentwindow] + range) &
  599.     (x > worldx[currentwindow] - range) & (y > worldy[currentwindow] - range))
  600.         return 1;
  601.     else return 0;
  602. }
  603.  
  604.  
  605.  
  606. short wscreen_coordx(short currentwindow, short xcoord)
  607. {
  608.   return (xcoord - worldx[currentwindow]);
  609. }
  610.  
  611.  
  612.  
  613. short wscreen_coordy(short currentwindow, short ycoord)
  614. {
  615.   return (ycoord - worldy[currentwindow]);
  616. }
  617.  
  618.  
  619.  
  620. void wcopymap (short source, short dest)
  621. {
  622.   mapwidth[dest]   = mapwidth[source];
  623.   mapheight[dest]  = mapheight[source];
  624.   scrollmaps[dest] = scrollmaps[source];
  625.     
  626.   worldmaxx[dest] = mapwidth[dest] * tilewidth[dest] 
  627.                     - (windowwidth[dest] * tilewidth[dest]) + 1;
  628.   worldmaxy[dest] = mapheight[dest] * tileheight[dest] 
  629.                     - (windowheight[dest] * tileheight[dest]) + 1;
  630. }
  631.